<?php

namespace app\api\validate;

use app\common\business\Category;
use app\common\business\WorkType;
use app\common\lib\Num;
use app\common\lib\Str;
use think\Validate;

class UserInfo extends Validate
{
    protected $rule = [
        'house_ids' => 'require|checkIds',
        'is_host' => ['require', "in" => "1,2"],
    ];

    protected $message = [
        'house_ids' => '房屋相关ID必须',
        'is_host.require' => '是否业主必须',
        'is_host.in' => '是否业主数值错误',
    ];

    protected function checkIds($value, $rule, $data = [])
    {
        $id_arr = explode(',',$value);

        if (count($id_arr) != 4){
            return '房屋数据错误';
        }

        $houseBis = new \app\common\business\House();

        $map = [
            ['id','in',$id_arr]
        ];
        $data = $houseBis->getListByWhere($map,0,0,'id,pid,name');
        if (empty($data) || count($data) != 4){
            return '未查询到房屋数据';
        }

        return true;
    }

    protected $scene = [
        'save'=> ['house_ids','is_host'],
    ];
}